package org.coc.iot.controller;

import lombok.extern.slf4j.Slf4j;
import org.coc.iot.common.utils.MenuUtils;
import org.coc.iot.common.utils.Utils;
import org.coc.iot.constants.Constants;
import org.coc.iot.ehcache.CacheConfiguration;
import org.coc.iot.ehcache.ManageEhCache;
import org.coc.iot.entity.SessionUser;
import org.coc.iot.entity.SysMenu;
import org.coc.iot.entity.SysRoleMenu;
import org.coc.iot.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Bean on 2017/5/14.
 */
@Slf4j
@Controller
public class FrameController extends BaseController {

    @Autowired
    private CacheConfiguration cacheConfiguration;

    @RequestMapping("/main.do")
    public String mainHandler(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
        SessionUser sessionUser = (SessionUser) request.getSession().getAttribute(Constants.SESSION_USER_KEY);
        EhCacheCacheManager manager
                = cacheConfiguration.ehCacheCacheManager(cacheConfiguration.ehCacheManagerFactoryBean());
        // 生成菜单
        MenuUtils mu = new MenuUtils();
        mu.initMenu(request, manager, sessionUser);
        return "main";
    }
}
